import * as types from './actionTypes';
import Immutable from 'seamless-immutable';
import {cache_set} from '../../utils/browserCache';

const initialState = Immutable({
    config:undefined,
    isLogged:undefined,
    inited:false,
    userInfo:undefined,
    showScrollToTopFloat:false,
    goTop:0,
    isScrolledBottom:false
});

export default function app(state = initialState, action = {}) {
    switch (action.type) {
        case types.SCROLLED_BOTTOM:
            return state.merge({
                isScrolledBottom:action.isScrolledBottom
            });
        case types.GO_TOP:
            return state.merge({
                goTop:action.flag
            });
        case types.SHOW_SCROLL_TO_TOP_FLOAT:
            return state.merge({
                showScrollToTopFloat:action.visible
            });
        case types.LOGIN_SUCESS:
            cache_set("app.isLogged",1)
            return state.merge({
                isLogged:true
            });
        case types.LOGOUT:
            //debugger;
            cache_set("app.isLogged",0);
            return state.merge({
                isLogged:false,
                inited:false
            });
        case types.INITED:
            //debugger;
            return state.merge({
                inited:true,
                userInfo:action.info.userInfo,
                config:action.info.appConfig
            });
        default:
            return state;
    }
}
